#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-

__license__="""
   Copyright 2004-2008 Henning von Bargen (henning.vonbargen arcor.de)
   This software is dual-licenced under the Apache 2.0 and the
   2-clauses BSD license. For details, see license.txt
"""

__version__=''' $Id: __init__.py,v 1.2 2004/05/31 22:22:12 hvbargen Exp $ '''

import os.path

import hyphenator

from hyphen import HyphenatedWord, HyphenationPoint

from ExplicitHyphenator import ExplicitHyphenator

class DictHyphenator(ExplicitHyphenator):

    def __init__ (self, 
                  language="EN",
                  minWordLength=4,
                  quality=8,
                  hyphenDir=None,
                  **options
                 ):
        ExplicitHyphenator.__init__(self,language=language,minWordLength=minWordLength,**options)
        if hyphenDir is None:
            hyphenDir = os.path.join(os.path.split(__file__)[0], "..", "dict")
        fname = os.path.join(hyphenDir, "hyph_%s.dic" % language)

        self.hy = hyphenator.Hyphenator(fname, left=2, right=2)
        self.quality = quality

    def _positions(self, word):
        return [ HyphenationPoint(i, self.quality, 0, self.shy, 0, u"") for i in self.hy.positions(word) ]
        
    def hyph(self, aWord):
        assert isinstance(aWord, unicode)
        hword = HyphenatedWord(aWord, hyphenations = self._positions(aWord))
        return hword

    def i_hyphenate(self, aWord):
        return ExplicitHyphenator.i_hyphenate_derived(self, aWord)
    
if __name__=="__main__":
    import sys
    h = DictHyphenator("ru", 3)
    for x in h.hyphenate(unicode(sys.argv[1], 'utf-8')).showHyphens():
        print x
    #h.test(outfname="PyHyphenLearn.html")
    
